/*
 * GlobalInfoPanel.cpp
 *
 *  Created on: 26-12-2010
 *      Author: Przemek
 */

#include "customUI/GlobalInfoPanel.hpp"
#include "world/World.hpp"
#include "world/visitors/IndividualsCounterVisitor.hpp"
#include "world/visitors/SuppliesCounterVisitor.hpp"
using namespace std;
using namespace boost;

GlobalInfoPanel::GlobalInfoPanel(const Dimension& parentSize)
{
	const float lineHeight = 20;
	const Dimension fullLineSize(parentSize.getWidth(), lineHeight);
	const Dimension halfLineSize(fullLineSize.getWidth() / 2, fullLineSize.getHeight());
	setSize(parentSize);

	Label* label = new Label("___Global info___", GLColor::RED);
	label->setSize(fullLineSize);
	add(label);

	float y = lineHeight;
	label = new Label("Population:   ");
	label->setBounds(geometry::Rectangle(Vector(0.0f, y), halfLineSize));
	add(label);

	populationLabel = new Label("0");
	populationLabel->setBounds(geometry::Rectangle(Vector(halfLineSize.getWidth(), y), halfLineSize));
	add(populationLabel);

	y += lineHeight;
	label = new Label("Meat:   ");
	label->setBounds(geometry::Rectangle(Vector(0.0f, y), halfLineSize));
	add(label);

	meatSuppliesLabel = new Label("0");
	meatSuppliesLabel ->setBounds(geometry::Rectangle(Vector(halfLineSize.getWidth(), y),
			halfLineSize));
	add(meatSuppliesLabel);

	y += lineHeight;
	label = new Label("Vegetables:   ");
	label->setBounds(geometry::Rectangle(Vector(0.0f, y), halfLineSize));
	add(label);

	vegetablesSuppliesLabel = new Label("0");
	vegetablesSuppliesLabel ->setBounds(geometry::Rectangle(Vector(halfLineSize.getWidth(), y),
			halfLineSize));
	add(vegetablesSuppliesLabel);

	y += lineHeight;
	label = new Label("Water:   ");
	label->setBounds(geometry::Rectangle(Vector(0.0f, y), halfLineSize));
	add(label);

	waterSuppliesLabel = new Label("0");
	waterSuppliesLabel ->setBounds(geometry::Rectangle(Vector(halfLineSize.getWidth(), y),
			halfLineSize));
	add(waterSuppliesLabel);
}

void GlobalInfoPanel::update()
{
	IndividualsCounterVisitor individualsCounter;
	SuppliesCounterVisitor suppliesCounter;
	individualsCounter.visitEveryElement(World::getInstance().getElements());
	suppliesCounter.visitEveryElement(World::getInstance().getElements());

	populationLabel->setText(lexical_cast<string> (individualsCounter.getCounter()));
	meatSuppliesLabel->setText(lexical_cast<string> (suppliesCounter.getMeatCounter()));
	vegetablesSuppliesLabel->setText(lexical_cast<string> (suppliesCounter.getVegetablesCounter()));
	waterSuppliesLabel->setText(lexical_cast<string> (suppliesCounter.getWaterCounter()));
}

